/**   
 * 项目名：五位一体化工安全信息平台
 * 日期：    2019-12-08 18:31:39  
 * Copyright (c) 2015- joysuch-版权所有     
 */

package com.joysuch.wwyt.core.repository;

import java.util.List;

import com.joysuch.wwyt.core.entity.BaseUserMenuFunction;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.transaction.annotation.Transactional;

/**
 * BaseUserMenuFunctionDao
 * 
 */
public interface BaseUserMenuFunctionDao
        extends JpaRepository<BaseUserMenuFunction, Long>, QuerydslPredicateExecutor<BaseUserMenuFunction> {
    public Page<BaseUserMenuFunction> findAll(Specification<BaseUserMenuFunction> spec, Pageable pageable);

    public BaseUserMenuFunction save(BaseUserMenuFunction bean);

    public void delete(BaseUserMenuFunction bean);

    @Query("select distinct(m.menuId) from BaseUserMenuFunction m where m.userId=?1")
    public List<Long> selectMenuIdsByUserId(Long userId);

    @Modifying
    @Transactional
    @Query("delete from BaseUserMenuFunction m where m.userId=?1 and m.menuId in (?2)")
    public void deleteByIds(Long userId, List<Long> ids);

    public List<BaseUserMenuFunction> findByUserIdAndMenuId(Long userId, Long menuId);


}
